﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;


namespace LetsGoToSchool
{
    /// <summary>
    /// parser for the music xml file
    /// </summary>
    class XMLParser
    {
        private MusicGame _game;

        public XMLParser(MusicGame game)
        {
            _game = game;
        }

        public static List<Note> readXML(String fileName) {
            List<Note> toReturn = new List<Note>();
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);
            if (doc.HasChildNodes)
            {
                foreach (XmlNode docNode in doc.ChildNodes)
                {
                    if (docNode.Name == "Song")
                    {
                        String path = docNode.Attributes.GetNamedItem("Path").InnerText;
                        foreach (XmlNode nodeNode in docNode.ChildNodes)
                        {
                            if (nodeNode.Name == "Note")
                            {
                                String name = nodeNode.Attributes.GetNamedItem("Pitch").InnerText;
                                Double duration = Convert.ToDouble(nodeNode.Attributes.GetNamedItem("Duration").InnerText);
                                toReturn.Add(new Note(duration, name));
                            }
                        }

                    }
                }
            }
            return toReturn;
        }
    }
}
